﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EightQueueLib;

namespace EightQueueConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Queen lastQueen = null;
            for (int i = 1; i <= 8; i++)
            {
                lastQueen = new Queen(i, lastQueen);
            }
            

            int sum = 1;
            while (lastQueen.Advance() && lastQueen.Left.Left.Left.Left.Left.Left.Left.Row == 1)
            {
                sum++;
                lastQueen.Print();
            }

            sum++;
            lastQueen.Print();

            while (lastQueen.Advance() && lastQueen.Left.Left.Left.Left.Left.Left.Left.Row != 1)
            {
                sum++;
                lastQueen.Print();
            }

            Console.WriteLine(sum);
            Console.ReadLine();
        }
    }

    static class QueenPrinter
    {
        public static void Print(this Queen q)
        {
            List<Queen> queenList = new List<Queen>();
            while (q != null)
            {
                queenList.Add(q);
                q = q.Left;
            }
            
            foreach (var queen in queenList.OrderBy(m => m.Row))
            {
                for (int i = 1; i < queen.Col; i++)
                {
                    Console.Write("0 ");
                }
                Console.Write("1 ");
                for (int i = queen.Col + 1; i <= 8; i++)
                {
                    Console.Write("0 ");
                }
                Console.WriteLine();
            }

            Console.WriteLine();
        }
    }
}
